import json
import sqlite3


def get_best():
    # 获取猜词效率最高的的开局成语
    with open('idiom_frq.json', mode='r', encoding='utf-8') as f:
        idiom_freq: dict = json.load(f)
    best = {}
    a = 0
    ss = ''
    for k in idiom_freq:
        conn = sqlite3.connect('idioms.sqlite')
        c = conn.cursor()
        sql = f'select word, freq, s1, s2, s3, s4, f1, f2, f3, f4, t1, t2, t3, t4 from STRICT where word like "{k}"'
        c.execute(sql)
        idioms = c.fetchone()
        if idioms:
            idiom = list(idioms)
            s = idiom[2:6]
            f = idiom[6:10]
            t = idiom[10:14]

            if len(set(s)) == 4 and len(set(f)) == 4 and len(set(t)) == 4:
                best[k] = idiom[1]
                ss = ss + f'|{k}|{idiom[1]}'
                a += 1
            if a == 3:
                ss = ss + f'|'
                print(ss)
                a = 0
                ss = ''
    # print(best)


best = {'长治久安': 18732, '一目了然': 17310, '无可厚非': 13090, '取而代之': 12053, '排忧解难': 11980, '举足轻重': 11820, '统筹兼顾': 10847,
        '热火朝天': 9846, '顺理成章': 7282, '死灰复燃': 6643, '大江南北': 6408, '无可争辩': 6047, '吃苦耐劳': 5983, '昏迷不醒': 5980, '一筹莫展': 5585,
        '百花齐放': 5578, '语重心长': 5502, '大张旗鼓': 5315, '轻描淡写': 4927, '不解之缘': 4914, '救死扶伤': 4851, '狂风暴雨': 4789, '叹为观止': 4764,
        '街头巷尾': 4673, '双管齐下': 4511, '刻骨铭心': 4440, '打成一片': 4161, '嘘寒问暖': 4004, '酸甜苦辣': 3773, '异口同声': 3745, '人声鼎沸': 3667,
        '得心应手': 3642, '袖手旁观': 3614, '始终不渝': 3581, '害群之马': 3557, '背井离乡': 3546, '轻重缓急': 3361, '剑拔弩张': 3166, '纸上谈兵': 3153,
        '火上浇油': 3036, '风调雨顺': 2927, '正本清源': 2865, '豁然开朗': 2519, '相濡以沫': 2475, '痛心疾首': 2458, '打破常规': 2386, '保家卫国': 2313,
        '满载而归': 2288, '瞒天过海': 2234, '峰回路转': 2218, '心满意足': 2190, '三足鼎立': 2179, '汗马功劳': 2138, '天罗地网': 2111, '以偏概全': 2035,
        '用心良苦': 2027, '步履维艰': 1991, '崇山峻岭': 1980, '信手拈来': 1932, '多管闲事': 1917, '周而复始': 1880, '一尘不染': 1832, '前因后果': 1827,
        '表面文章': 1800, '花团锦簇': 1787, '心领神会': 1742, '遍体鳞伤': 1736, '铁证如山': 1694, '身不由己': 1673, '不堪回首': 1673, '一反常态': 1618,
        '先睹为快': 1606, '枪林弹雨': 1598, '无懈可击': 1571, '雨过天晴': 1535, '回心转意': 1524, '妙语连珠': 1503, '姹紫嫣红': 1501, '见多识广': 1498,
        '大雨倾盆': 1497, '逆水行舟': 1475, '思前想后': 1442, '答非所问': 1432, '弄巧成拙': 1408, '口干舌燥': 1384, '灯红酒绿': 1383, '砸锅卖铁': 1368,
        '神通广大': 1359, '天南地北': 1347, '墨守成规': 1308, '繁花似锦': 1301, '柳暗花明': 1298, '铁面无私': 1229, '狼吞虎咽': 1214, '万马奔腾': 1194,
        '赤手空拳': 1192, '光彩夺目': 1183, '五光十色': 1167, '因循守旧': 1154, '去伪存真': 1122, '广开言路': 1116, '百年之后': 1112, '四脚朝天': 1111,
        '破釜沉舟': 1100, '马到成功': 1082, '痛改前非': 1079, '杀人灭口': 1072, '为非作歹': 1063, '由浅入深': 1058, '装聋作哑': 1054, '分庭抗礼': 1053,
        '劈头盖脸': 1053, '无价之宝': 1052, '乔装打扮': 1049, '画龙点睛': 1040, '胡思乱想': 1040, '扫地出门': 1017, '别有洞天': 1004, '一年半载': 984,
        }

if __name__ == '__main__':
    get_best()
